﻿Imports System.Data
Imports FirebirdSql.Data
Imports FirebirdSql.Data.FirebirdClient

Public Class _VagaTrabalho
    Inherits _DataBase

    Private emp As _empregador

    Private _idVagaDeTrabalho As Integer
    Public Property idVagaDeTrabalho() As Integer
        Get
            Return _idVagaDeTrabalho
        End Get
        Set(ByVal value As Integer)
            _idVagaDeTrabalho = value
        End Set
    End Property
    Private _idEmpregador As Integer
    Public Property idEmpregador() As Integer
        Get
            Return _idEmpregador
        End Get
        Set(ByVal value As Integer)
            _idEmpregador = value
        End Set
    End Property
    Private _idCargoFuncao As Integer
    Public Property idCargoFuncao() As Integer
        Get
            Return _idCargoFuncao
        End Get
        Set(ByVal value As Integer)
            _idCargoFuncao = value
        End Set
    End Property
    Private _dtCadastro As Date
    Public Property dtCadastro() As Date
        Get
            Return _dtCadastro
        End Get
        Set(ByVal value As Date)
            _dtCadastro = value
        End Set
    End Property
    Private _dsAtivBenReq As String
    Public Property dsAtivBenReq() As String
        Get
            Return _dsAtivBenReq
        End Get
        Set(ByVal value As String)
            _dsAtivBenReq = value
        End Set
    End Property
    Private _qtVagas As Integer
    Public Property qtVagas() As Integer
        Get
            Return _qtVagas
        End Get
        Set(ByVal value As Integer)
            _qtVagas = value
        End Set
    End Property
    Private _dsInfRecrutador As String
    Public Property dsInfRecrutador() As String
        Get
            Return _dsInfRecrutador
        End Get
        Set(ByVal value As String)
            _dsInfRecrutador = value
        End Set
    End Property
    Private _stPNE As Integer
    Public Property stPNE() As Integer
        Get
            Return _stPNE
        End Get
        Set(ByVal value As Integer)
            _stPNE = value
        End Set
    End Property
    Private _dsPNE As String
    Public Property dsPNE() As String
        Get
            Return _dsPNE
        End Get
        Set(ByVal value As String)
            _dsPNE = value
        End Set
    End Property
    Private _stAtivo As Integer
    Public Property stAtivo() As Integer
        Get
            Return _stAtivo
        End Get
        Set(ByVal value As Integer)
            _stAtivo = value
        End Set
    End Property
    Private _dtBauxa As Date
    Public Property dtBaixa() As Date
        Get
            Return _dtBauxa
        End Get
        Set(ByVal value As Date)
            _dtBauxa = value
        End Set
    End Property
    Private _idEncaminhamento As Integer
    Public Property idEncaminhamento() As Integer
        Get
            Return _idEncaminhamento
        End Get
        Set(ByVal value As Integer)
            _idEncaminhamento = value
        End Set
    End Property

    Private _nmEmpresa As String
    Public Property nmEmpresa() As String
        Get
            Return _nmEmpresa
        End Get
        Set(ByVal value As String)
            _nmEmpresa = value
        End Set
    End Property

    Private _dsCargo As String
    Public Property dsCargo() As String
        Get
            Return _dsCargo
        End Get
        Set(ByVal value As String)
            _dsCargo = value
        End Set
    End Property

    Private _idMotivo As Integer
    Public Property idMotivo() As Integer
        Get
            Return _idMotivo
        End Get
        Set(ByVal value As Integer)
            _idMotivo = value
        End Set
    End Property

    Public Sub geraXmlVagasDeTrabalho()


        Dim s() As String = {"O_DT_CADASTRO"}  '<-- Campos a serem filtrados
        Dim f As New FiltroDateTimeXml("C:\SATE\TEMP\RptVagasDeTrabalho", s)
        consultaVagasAtivas.WriteXml(f, XmlWriteMode.WriteSchema) '<-- DataSet
        f.Close() '<-- Libera referência ao arquivo

    End Sub
    Private Function consultaVagasAtivas() As DataSet
        conectaDb()
        consultaVagasAtivas = retornaDataSet(montaParametrosSQL("SP_VAGADETRABALHO_CONSULTA", "RELATORIO"))
        desconectaDb()
    End Function

    Public Function consultaVagaPorId(ByVal pIdVaga As Integer) As Boolean
        idVagaDeTrabalho = pIdVaga

        conectaDb()
        dr = retornaDataReader(montaParametrosSQL("SP_VAGADETRABALHO_CONSULTA", "ID"))
        With dr
            If .Read Then
                idEmpregador = .Item("O_ID_EMPREGADOR")
                nmEmpresa = .Item("O_NM_EMPREGADOR")
                idCargoFuncao = .Item("O_ID_CARGOFUNCAO")
                dsCargo = .Item("O_DS_CARGOFUNCAO")
                dtCadastro = .Item("O_DT_CADASTRO")
                dsAtivBenReq = .Item("O_DS_ATIVBENREQ")
                qtVagas = .Item("O_QT_VAGAS")
                dsInfRecrutador = .Item("O_DS_INFRECRUTADOR")
                stPNE = .Item("O_ST_PNE")
                dsPNE = .Item("O_DS_PNE")
                stAtivo = .Item("O_ST_ATIVA")
            End If
        End With
        desconectaDb()

    End Function

    Public Function consultaEncaminhamentosPorIdVaga(ByVal pIdVaga As Integer) As DataSet
        idVagaDeTrabalho = pIdVaga
        conectaDb()
        consultaEncaminhamentosPorIdVaga = retornaDataSet(montaParametrosSQL("SP_VAGADETRABALHO_CONSULTA", "ENC"))
        desconectaDb()

    End Function
    Public Function consultaVagasDeTrabalhador() As DataSet
        conectaDb()
        consultaVagasDeTrabalhador = retornaDataSet(montaParametrosSQL("SP_VAGADETRABALHO_CONSULTA", "RESUMIDO"))
        desconectaDb()
    End Function

    Public Function insereVagaDeTrabalho() As Integer
        conectaDb()
        insereVagaDeTrabalho = execSQL(montaParametrosSQL("SP_VAGADETRABALHO_CMD", "INSERIR"))
        desconectaDb()
    End Function

    Public Sub alteraVagaDeTrabalho(ByVal pIdVagaDeTrabalho As Integer)
        idVagaDeTrabalho = pIdVagaDeTrabalho
        conectaDb()
        execSQLSemRetorno(montaParametrosSQL("SP_VAGADETRABALHO_CMD", "ALTERAR"))
        desconectaDb()
    End Sub
    Public Sub efetuarBaixaVagaAberta(ByVal pidVaga As Integer, _
                                       ByVal pIdMotivo As Integer, _
                                       ByVal pDtBaixa As Date)
        idVagaDeTrabalho = pidVaga
        idMotivo = pIdMotivo
        dtBaixa = pDtBaixa
        conectaDb()
        execSQLSemRetorno(montaParametrosSQL("SP_VAGADETRABALHO_CMD", "BAIXAR"))
        desconectaDb()

    End Sub

    Private Function montaParametrosSQL(ByVal nomeSP As String, ByVal pModo As String) As FbCommand
      
        With cmd
            .CommandText = nomeSP
            With .Parameters
                .Clear()
                .Add("MODO", FbDbType.VarChar, 10).Value = pModo
                .Add("I_ID_VAGADETRABALHO", FbDbType.Integer).Value = idVagaDeTrabalho
                .Add("I_ID_EMPREGADOR", FbDbType.Integer).Value = idEmpregador
                .Add("I_ID_CARGOFUNCAO", FbDbType.Integer).Value = idCargoFuncao
                .Add("I_DT_CADASTRO", FbDbType.Date).Value = dtCadastro
                .Add("I_DS_ATIVBENREQ", FbDbType.VarChar, 250).Value = dsAtivBenReq
                .Add("I_QT_VAGAS", FbDbType.Integer).Value = qtVagas
                .Add("I_DS_INFRECRUTADOR", FbDbType.VarChar, 180).Value = dsInfRecrutador
                .Add("I_ST_PNE", FbDbType.Integer).Value = stPNE
                .Add("I_DS_PNE", FbDbType.VarChar, 80).Value = dsPNE
                .Add("I_ST_ATIVA", FbDbType.Integer).Value = stAtivo
                .Add("I_DT_BAIXA", FbDbType.Date).Value = dtBaixa
                .Add("I_ID_MOTIVO", FbDbType.Integer).Value = idMotivo
                .Add("I_ID_ENCAMINHAMENTO", FbDbType.Integer).Value = idEncaminhamento


            End With
        End With
        Return cmd
    End Function
End Class

